Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / androidApp / src / test / kotlin / org / meshtastic / app / widget / GlanceTrampolineManifestTest.kt

Displaying Raw • Download

androidApp/src/test/kotlin/org/meshtastic/app/widget/GlanceTrampolineManifestTest.kt bd2863243bab6eb213401d949839a2bc74dde7e2 (bd286324) Text, 3.97 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.app.widget

Tff7b72import T7ee787android.app.Application
Tff7b72import T7ee787android.content.ComponentName
Tff7b72import T7ee787android.content.Context
Tff7b72import T7ee787android.content.pm.PackageManager
Tff7b72import T7ee787androidx.test.core.app.ApplicationProvider
Tff7b72import T7ee787org.junit.runner.RunWith
Tff7b72import T7ee787org.robolectric.RobolectricTestRunner
Tff7b72import T7ee787org.robolectric.annotation.Config
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertFailsWith
Tff7b72import T7ee787kotlin.test.assertFalse

T8b949e/**
* Guards the `tools:node="remove"` of `androidx.glance.appwidget.action.ActionTrampolineActivity` in
* `androidApp/src/main/AndroidManifest.xml`.
*
* That activity's `onCreate` unconditionally `require()`s an `"ACTION_INTENT"` Intent extra, so any launch without it
* is a FATAL `IllegalArgumentException` ("List adapter activity trampoline invoked without specifying target intent")
* raised before any of our code runs. Nothing can supply the extra, because nothing in Glance ever creates the intent:
* `applyTrampolineIntent()` selects this component only for `ActionTrampolineType.ACTIVITY`, and no call site passes
* `ACTIVITY` — the lazy-collection call sites all pass `BROADCAST`/`SERVICE`/`FOREGROUND_SERVICE`, which route to
* [androidx.glance.appwidget.action.InvisibleActionTrampolineActivity] instead. It is dead-but-launchable library code,
* so we take it out of the merged manifest entirely.
*
* These assertions run against the *merged* manifest (Robolectric reads it, which is why the AAR-declared invisible
* trampoline resolves), so they fail if the removal is dropped or if a Glance bump reshuffles these components.
*/
Tf0883e@RunWithTb4b4b4(Te6edf3RobolectricTestRunnerTff7b72::Te6edf3classTb4b4b4)
Tf0883e@ConfigTb4b4b4(Te6edf3application Tff7b72= Te6edf3ApplicationTff7b72::Te6edf3classTb4b4b4, Te6edf3sdk Tff7b72= Tff7b72[T79c0ff3T79c0ff4Tff7b72]Tb4b4b4)
Tff7b72class T56d364GlanceTrampolineManifestTest Tb4b4b4{

Tff7b72private Tff7b72val Te6edf3contextTb4b4b4: Te6edf3Context Tff7b72= Te6edf3ApplicationProviderTb4b4b4.Te6edf3getApplicationContextTb4b4b4(Tb4b4b4)

Tf0883e@Test
Tff7b72fun Td2a8ff`crash-on-launch activity trampoline is absent from the merged manifest`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertFailsWithTff7b72<Te6edf3PackageManagerTb4b4b4.Te6edf3NameNotFoundExceptionTff7b72>Tb4b4b4(
Ta5d6ff"Tffd700$Te6edf3ACTION_TRAMPOLINETa5d6ff is declared in the merged manifest. Glance never targets it, and its onCreate Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffrequire()s an ACTION_INTENT extra, so every launch is a FATAL IllegalArgumentException. Restore Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffthe tools:node=Ta5d6ff\"Ta5d6ffremoveTa5d6ff\"Ta5d6ff entry in androidApp/src/main/AndroidManifest.xml.Ta5d6ff"Tb4b4b4,
Tb4b4b4) Tb4b4b4{
Te6edf3contextTb4b4b4.Te6edf3packageManagerTb4b4b4.Te6edf3getActivityInfoTb4b4b4(Te6edf3ComponentNameTb4b4b4(Te6edf3contextTb4b4b4, Te6edf3ACTION_TRAMPOLINETb4b4b4)Tb4b4b4, T79c0ff0Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`invisible trampoline Glance actually uses is still declared and not exported`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Positive control: proves the merged manifest under test really does include glance-appwidget's own
T8b949e// components, so the assertion above is a genuine absence rather than a manifest that was never merged.
Tff7b72val Te6edf3activityInfo Tff7b72= Te6edf3contextTb4b4b4.Te6edf3packageManagerTb4b4b4.Te6edf3getActivityInfoTb4b4b4(Te6edf3ComponentNameTb4b4b4(Te6edf3contextTb4b4b4, Te6edf3INVISIBLE_TRAMPOLINETb4b4b4)Tb4b4b4, T79c0ff0Tb4b4b4)

Te6edf3assertFalseTb4b4b4(
Te6edf3activityInfoTb4b4b4.Te6edf3exportedTb4b4b4,
Ta5d6ff"Tffd700$Te6edf3INVISIBLE_TRAMPOLINETa5d6ff must stay unexported — it launches intents handed to it verbatim.Ta5d6ff"Tb4b4b4,
Tb4b4b4)
Tb4b4b4}

Tff7b72private Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72const Tff7b72val Te6edf3ACTION_TRAMPOLINE Tff7b72= Ta5d6ff"Ta5d6ffandroidx.glance.appwidget.action.ActionTrampolineActivityTa5d6ff"
Tff7b72const Tff7b72val Te6edf3INVISIBLE_TRAMPOLINE Tff7b72= Ta5d6ff"Ta5d6ffandroidx.glance.appwidget.action.InvisibleActionTrampolineActivityTa5d6ff"
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.07s